package com.example.fyptest3;

import java.io.File;

import android.net.Uri;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

public class InsideAlbumActivity extends Activity implements View.OnClickListener{

	File[] file;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_inside_album);
		
		//get data from previous activity
		Intent intentAlbum = getIntent();
		String s = intentAlbum.getExtras().getString("album_dir");
		
		//change title bar text
		File f = new File(s);
		file = f.listFiles();
		setTitle("<< Albums  -  "+f.getName().toString());
		
		//change title bar color to CYAN
		ActionBar bar = getActionBar();
		bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00C4CD")));
		
		//change title bar text to WHITE
		int actionBarTitleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
		if (actionBarTitleId >0){
			TextView title = (TextView)findViewById(actionBarTitleId);
			if (title != null){
				title.setTextColor(Color.WHITE);
			}
		}
		
//	Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();
		GridView gridview = (GridView)findViewById(R.id.gridView1);
		gridview.setAdapter(new ImageAdapter(this, s));
		
		gridview.setOnItemClickListener(new OnItemClickListener(){
			  public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
		          //  Toast.makeText(InsideAlbumActivity.this, "" + position, Toast.LENGTH_SHORT).show();
				  	Intent intent = new Intent(InsideAlbumActivity.this, FullScreenImageActivity.class);
					//String path = file[v.getId()].toString();
				  	String path = file[position].toString();
					String image_n = file[position].getName();
					intent.putExtra("image_path", path);
					intent.putExtra("image_name", image_n);
					intent.putExtra("image_pos", position);
					startActivity(intent);
				
		        }
			
		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_inside_album, menu);
		return true;
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		
	}

}
